package com.example.springbootdemo.service;

import com.example.springbootdemo.entity.UserCase;
import com.example.springbootdemo.repository.UserCaseRepository;
import com.example.springbootdemo.validator.UserCaseValidator;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Gong.Yang
 */
@Service
@RequiredArgsConstructor
public class UserCaseService {
    private final UserCaseRepository userCaseRepository;
    private final UserCaseValidator userCaseValidator;


    public List<UserCase> findList() {
        return userCaseRepository.selectList();
    }

    public UserCase findItem(String id) {
        return userCaseRepository.selectById(id);
    }

    public UserCase create(UserCase userCase) {
        userCaseValidator.createValidate(userCase);
        userCaseRepository.insert(userCase);
        return userCase;
    }

    public UserCase modify(UserCase userCase) {
        userCaseValidator.modifyValidate(userCase);
        userCaseRepository.updateById(userCase);
        return userCase;
    }

    public void delete(String id) {
        userCaseValidator.deleteValidate(id);
        userCaseRepository.deleteById(id);
    }

}
